|
|
|
|
|
|
|
As you have seen, designing a report involves setting up the report data source and page layout. After you create a report, you have basically three ways to get the report to the users: |
|
|
|
|
|
|
|
|
Call the Show method to display a report onscreen in a print preview window. The users can browse the information and print a copy if desired. |
|
|
|
|
|
|
|
|
Execute the PrintReport method to bypass the preview screen and print directly to the printer. This method is useful if you are automating reports, or your program already displays the data and therefore a preview is not necessary. |
|
|
|
|
|
|
|
|
Use the ExportReport method to save the contents of the report to a file. This function can be used to create a Web page from your reports. |
|
|
|
|
|
|
|
|
In an earlier example, you learned how to use the Show method to display the report on the screen. Calling one of the other two methods to choose a different option is just as easy. |
|
|
|
|
|
|
|
|
Using the PrintReport Method |
|
|
|
|
|
|
|
|
In its simplest form, a call to the PrintReport method might look like this: |
|
|
|
|
|
|
|
|
However, you can use several optional parameters to achieve more control over printing: |
|
|
|
|
|
|
|
|
ShowDialogThis parameter determines whether the Windows printer dialog box is shown, allowing users to cancel the operation or adjust printer settings. (This parameter is False by default.) |
|
|
|
|
|
|
|
|
RangeThis parameter controls whether every page of the report is printed or just the pages you specify. The default setting is rptRangeAllPages, which causes every page to be printed. |
|
|
|
|
|
|
|
|
PageFrom and PageToIf the Range parameter is set to rptRangeFromTo, these two parameters determine the starting and ending pages of the printed report. |
|
|
|
|
|
|
|
|
The following line of code uses all the optional parameters so that only page 5 is printed: |
|
|
|
|
|
|
|
|
datareport1.PrintReport True,rptRangeFromTo,5,5 |
|
|
|
|
|
|
|
|
Note that if the ShowDialog property is set to True, users can modify the page range or cancel the print job. |
|
|
|
|
|
|
|
|
Using the ExportReport Method |
|
|
|
|
|
|
|
|
To export a report to an HTML or text file, use the ExportReport method. For example, the following line of code creates an HTML page containing your report: |
|
|
|
|
|
|
|
|
datareport1.ExportReport "key_def_HTML","D:\Temp\MyReport.HTM",True,False |
|
|
|
|
|
|
|
|
As with PrintReport, ExportReport has several optional parameters: |
|
|
|
|
|
|
|
|
FormatIndexOrKeyIdentifies the format of the export file. Four available formats are stored in the ExportFormats collection, but the choice is basically between text or HTML. |
|
|
|
|
|